home *** CD-ROM | disk | FTP | other *** search
- /* bt_cache.c - cache index blocks to cut Disk I/O */
- /* this version handles only a single open index file */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- extern IX_DESC *pci ; /* refers to index descriptor */
- /* for current function call */
-
- int init_cache() /* initilize blockio cache */
- {
- int l ;
-
- for(l=0 ;l < MAX_LEVELS ; l=l+1 )
- { pci->cache[l].brec = NULLREC ; /* nothing in memory yet */
- }
- }
-
- int chk_cache(l,r) /* check cache for an index block */
- int l ; /* index level for this block */
- RECPOS r ; /* block's location in index file */
- {
- BLOCK *pb ;
-
- if( pci->cache[l].brec != r )
- return( 0 ) ;
- return( 1 ) ;
- }
-
- int get_cache(l,r,to) /* get a block from the cache */
- int l ; /* index level for this block */
- RECPOS r ; /* block's location in index file */
- BLOCK *to ; /* if found, copy it here */
- {
- BLOCK *pb ;
-
- if( pci->cache[l].brec != r )
- return( 0 ) ;
- pb = & pci->cache[l] ;
- mover(to,pb, sizeof(BLOCK) ) ; /* copy it */
- pb->brec = r ;
- return( 1) ;
- }
-
- int put_cache(l,pb) /* write an index block back to file */
- int l ;
- BLOCK *pb ; /* address of index block */
- {
- BLOCK *to ;
-
- to = & pci->cache[l] ;
- mover(to,pb, sizeof(BLOCK) ) ; /* copy whole block */
- }
-
- int scrub_cache(r) /* remove a block from the cache */
- RECPOS r ; /* the block's file position */
- { /* = RECPOS scrubs all levels */
- int l ;
-
- for(l=0 ; l < pci->dx.nl ; l=l+1) /* search the cache */
- { if( (r == NULLREC) || ( r == pci->cache[l].brec) )
- pci->cache[l].brec = NULLREC ;
- }
- }
-
-